const setCookie = function(name, value, daysToLive) {
    let cookie = name + "=" + encodeURIComponent(value);
    if (typeof daysToLive === "number") {
      //按天算
      cookie +=";path=/"+ "; max-age=" + daysToLive * 24 * 60 * 60;
    }
    document.cookie = cookie;
  }
 const getCookie = function(name) {
    let cookieArr = document.cookie.split(";");
    for (let i = 0; i < cookieArr.length; i++) {
      let cookiePair = cookieArr[i].split("=");
      if (name == cookiePair[0].trim()) {
        // 解码cookie值并返回
        return decodeURIComponent(cookiePair[1]);
      }
    }
    return null;
  }

  export {setCookie, getCookie}